import update from './atom/db/update';
import { IBaseTable } from './atom/db/interfaces';

declare const action_id: string;
declare const session_id: string;
declare const spaceid: string;

interface Message {
	_id: string;
	no: string;
	name: string;
	confirm_date: string;
	effectivedate: string;
	staus: string;
	purchase_right: string;
	enddate: string;
	org_name: string;
	memo: string;
	accessory_url: string;
	certificate: string;
}

interface teachStaff extends IBaseTable {
	staff_number: string;
	staff_name: string;
	deptid: string;
	deptname: string;
}

async function atom(msg: Message) {
	const systemid = '6051';

	const { prepare, exec } = update(action_id, session_id, spaceid, systemid);

	const effectivedate = (msg.effectivedate === '0') ? 0 : (new Date(msg.effectivedate).getTime());
	const enddate = (msg.enddate === '0') ? 0 : (new Date(msg.enddate).getTime());

	prepare('certifi_info', [{ _id: msg._id, no: msg.no, name: msg.name, confirm_date: new Date(msg.confirm_date).getTime(), effectivedate, enddate, staus: msg.staus, purchase_right: msg.purchase_right, org_name: msg.org_name, memo: msg.memo, accessory_url: msg.accessory_url, certificate: msg.certificate }]);

	const res = await exec();

	if (res.code === 1) {
		return 'success';
	} else {
		return 'fail';
	}
}